﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CToolsWin.DB
{
    public partial class SQLConnStr : Form
    {
        public SQLConnStr()
        {
            InitializeComponent();
            cbbSqlConn.Items.Add("其它");
        }
        private string joinSQLConn()
        {
            if (string.IsNullOrEmpty(txtSourceIP.Text.Trim()))
                txtSourceIP.Text = ".";
            if (string.IsNullOrEmpty(txtCatalog.Text.Trim()))
                txtCatalog.Text = "master";
            if (rbtnSecuritySQL.Checked)
                return "Data Source=" + txtSourceIP.Text + ";Initial Catalog=" + txtCatalog.Text + ";uid=" + txtUid.Text + ";pwd=" + txtPwd.Text + ";";
            else
                return "Data Source=" + txtSourceIP.Text + ";Initial Catalog=" + txtCatalog.Text + ";Integrated Security=SSPI;";
        }

        private void btnJoin_Click(object sender, EventArgs e)
        {
            txtSQLConnStr.Text = joinSQLConn();
        }

        private void btnJoinAndEncrypt_Click(object sender, EventArgs e)
        {
            txtSQLConnStr.Text = joinSQLConn();
            txtSQLConnStrNew.Text = Common.Tools.Encrypt.DES.Encrypt(txtSQLConnStr.Text);
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string sqlConnStr = txtSQLConnStr.Text;
            txtSQLConnStrNew.Text = Common.Tools.Encrypt.DES.Encrypt(sqlConnStr);
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            string sqlConnStr = txtSQLConnStrNew.Text;
            txtSQLConnStr.Text = Common.Tools.Encrypt.DES.Decrypt(sqlConnStr);
        }

        private void rbtnSecurityWin_CheckedChanged(object sender, EventArgs e)
        {
            txtUid.Enabled = false;
            txtPwd.Enabled = false;
        }

        private void rbtnSecuritySQL_CheckedChanged(object sender, EventArgs e)
        {
            txtUid.Enabled = true;
            txtPwd.Enabled = true;
        }

        private void btnTestConn_Click(object sender, EventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }

        private void cbbSqlConn_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cbbSqlConn_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
